﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

/// <summary>
/// see description here 
/// http://www.microsoft.com/germany/msdn/solve/knowhow/howto/cliententwicklung/WieStelleIchDatenAusEinerDatenbankInWPFDar.mspx
/// </summary>
public class DatabaseTransaction
{
    #region Members

    public string dataSource, databaseName, connectionString, command;

    #endregion Members

    #region Construct

    /// <summary>
    /// @"Data Source=CLAUDE-PC;Initial Catalog=DocsRoomManagement;Integrated Security=True"
    /// </summary>
    /// <param name="dataSource">CLAUDE-PC</param>
    /// <param name="databaseName">DocsRoomManagement</param>
    public DatabaseTransaction(string dataSource, string databaseName)
	{
        connectionString = @"Data Source=" + dataSource + ";Initial Catalog=" + databaseName + ";Integrated Security=True";
        
	}
    #endregion Construct

    #region Methods

    public string setSelectCommand(string requestString)
    {
        try 
        {
            SqlConnection connection = new SqlConnection(connectionString);
            SqlCommand command = new SqlCommand(requestString, connection);

            connection.Open(); 
        }
        catch(Exception e){
            return e.ToString();
        }        
        
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="command">string cmd = "SELECT FirstName,LastName,EmailAddress 
    ///FROM Person.Contact 
    ///WHERE ContactID=" + textBox1.Text;</param>
    /// <returns></returns>
    public SqlDataReader getResultOfTheRequest(SqlCommand command)
    {
        SqlDataReader reader = command.ExecuteReader();

        if (reader.Read())
        {
            return reader;
        }
        connection.Close();
    }

    #endregion Methods

}
